export default class SeverSwitchRequest {

    static  url = 'https://ga.gametdd.com/adCtrl/agd/conf';
    // static  data = {'id': '6736f12ac5b6582182fb7d9b'};
    static  data = {
        // 'id': '6736f2dfc5b6582182fb7d9f',
        'id': '673c5fd8c5b6582182fb7e20',
        'sceneFrom':''
    };

    static xhr = new XMLHttpRequest();

    static RequestSwitchById(id:string,successCall:(data:any)=>void,failCall:(data:any)=>void){
        if (id==null||id == ""){
        
        }
        else{
            SeverSwitchRequest.data.id = id;
        }
        let data = SeverSwitchRequest.data;
        SeverSwitchRequest.data.sceneFrom= cc.sys.localStorage.getItem('sceneFrom')
        let xhr=SeverSwitchRequest.xhr;
        console.log("JQX测试开关"+ SeverSwitchRequest.data);
        console.log(SeverSwitchRequest.data);

        xhr.open('POST', SeverSwitchRequest.url, true);
        xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
        const postData = JSON.stringify(data);
        xhr.send(postData);
        xhr.onload = function () {
            if (xhr.status == 200) {
                const re = JSON.parse(xhr.responseText);
                //处理后续逻辑
              
                console.log("'请求服务器开关成功!'",re);
                successCall&&successCall(re);
            } else {
                //处理失败逻辑
                console.error('请求api失败!' + xhr.status);
                failCall&&failCall(xhr.status);
            }
        }; 


    }
  
}
